/**
    ATClab - scriptable Air Traffic Control simulations.
    Copyright (C) 2010 openatclab@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
**/

#ifndef __AIRCRAFT_TOOLS_HDR__
#define __AIRCRAFT_TOOLS_HDR__ 


#define POINT          std::pair< double, double >
#define HISTORY_DOTS   std::vector< Q3CanvasEllipse * >

#include "canvas_types.h"
#include <q3canvas.h>
#include <deque>
#include <vector>


//
// Qt classes
//
class Q3CanvasLine;
class Q3CanvasRectangle;
class Q3CanvasText;


namespace atc {

	//
	// atc
	//
	struct AircraftPathToken;
	class AircraftSprite;
	class Canvas;

    //
    // atc::ACProbeTool
    //

    class ACProbeTool : public Q3CanvasLine {

    public:
        ACProbeTool( Canvas *, AircraftSprite * );
        ~ACProbeTool();

    public:
		int  value() const;

		void deactivate();
		void toggle();
		void update();

	private:

	private:
		AircraftSprite *_sprite;
		Canvas         *_canvas;
		int             _idx;
		int             _mins;

		HISTORY_DOTS    _dots;
	};


    //
    // atc::ACHistoryTool
    //

    class ACHistoryTool {

    public:
        ACHistoryTool( Canvas *, AircraftSprite * );
        ~ACHistoryTool();

    public:
		void toggle();
		void update();

		void set_colour( const QColor & );
		void set_visible( bool );

		bool is_visible() const;

	private:

	private:
		AircraftSprite *_sprite;
		Canvas         *_canvas;
		HISTORY_DOTS    _dots;

	};


	//
	//
	//

	typedef HISTORY_DOTS HistoryDots;


	//
	// atc::
	//

	class ACTRouteLine;


    //
    // atc::ACRouteTool
    //
    class ACRouteTool {

	private:
		class RouteSection{

		public:
			RouteSection( ACTRouteLine *, Q3CanvasText *, Q3CanvasRectangle * );
			RouteSection( const RouteSection & );

			void destroy() const;

			friend class ACRouteTool;
			friend class ACTRouteLine;

		private:
			~RouteSection();

		private:
			ACTRouteLine     *path;
			Q3CanvasText      *time;
			Q3CanvasRectangle *back;
		};

    public:
        ACRouteTool( Canvas *, AircraftSprite * );
        ~ACRouteTool();

		friend class ACTRouteLine;

	public:
		bool is_active() const;

		void set_active( bool );

		void toggle();
		void update();

		void reroute( const AircraftPathToken *, const QPoint & );

	private:
		void clear();
		void build();

		void set_time();
		void set_visible( RouteSection *, bool );
		
		RouteSection* create_section( const AircraftPathToken * );

	private:
		AircraftSprite *_aircraft;
		Canvas         *_canvas;

		std::deque< RouteSection* >  _route;
		Q3CanvasLine	                *_track;

		bool   _shown;
		QColor _paint;

	public:
	    typedef std::deque< RouteSection* > RouteSections;

	};

	//
	// atc::ACTRouteLine
	//
	class ACTRouteLine : public Q3CanvasLine {

    public:
		ACTRouteLine( ACRouteTool *, const AircraftPathToken * );

		friend class ACRouteTool;

	public:
		AircraftSprite* aircraft() const;
		void reroute( const QPoint & );

    public: //virtual
		int rtti() const { return CanvasItem::RTTI_AC_ROUTEPATH; }

	private:
		ACRouteTool             *_parent;
		const AircraftPathToken *_data;

	};


};

#undef HISTORY_DOTS
#undef POINT

#endif
